<template>
  <!-- 跑马灯与机器人 -->
  <el-dialog :visible.sync="isShow" v-if="isShow" title="机器人信息" width="50%" :before-close="handleClose" top="100px" :close-on-click-modal="false">
    <div class="border-box">
      <el-form ref="robotForm" :model="formParams" :rules="ruleForm" label-position="right" label-width="0">
        <div class="flex item-box" v-for="(item,index) in itemData" :key="index">
          <div class="title width25">
            {{ item.label }}<span :class="item.pass?'mustPass':'noMustPass'">*</span>
          </div>
          <div class="content width80">
            <el-form-item class="item-clear" v-show="item.key=='a_robot_nametype'" label="" prop="a_robot_nametype">
              <el-select v-model="formParams.a_robot_nametype" placeholder="请选择游戏类型" filterable >
                <el-option label="暂无" :value="0"></el-option>
                <el-option :label="item.label" :value="item.value" v-for="(item, index) in GAME_TYPE" :key="index"></el-option>
              </el-select>
            </el-form-item>
            <el-form-item class="item-clear" v-show="item.key=='a_robot_room'" label="" prop="a_robot_room">
              <el-input-number :min="0" :max="999999999" :precision="0" v-model="formParams.a_robot_room" controls-position="right" clearable placeholder="请输入机器人ID" />
            </el-form-item>
            <el-form-item  class="item-clear" v-show="item.key=='a_robot_name'" label="" prop="a_robot_name">
              <el-input class="width40" type="text" v-model="formParams.a_robot_name" clearable placeholder="请输入机器人名称"></el-input>
            </el-form-item>
            <el-form-item class="item-clear" v-show="item.key=='a_robot_type'" label="" prop="a_robot_type">
              <el-radio-group v-model="formParams.a_robot_type">
                <el-radio-button :label="1">提现跑马灯</el-radio-button>
                <el-radio-button :label="2">赢钱跑马灯</el-radio-button>
              </el-radio-group>
            </el-form-item>
            <el-form-item class="item-clear" v-show="item.key=='a_robot_money_1'" label="" prop="a_robot_money_1">
              <el-input-number :min="0" :max="999999999" :precision="0" v-model="formParams.min_money_1" controls-position="right" clearable placeholder="请输入提现金额Min"/>
              —
              <el-input-number :min="0" :max="999999999" :precision="0" v-model="formParams.max_money_1" controls-position="right" clearable placeholder="请输入提现金额Max"/>
            </el-form-item>
            <el-form-item class="item-clear" v-show="item.key=='a_robot_money_2'" label="" prop="a_robot_money_2">
              <el-input-number :min="0" :max="999999999" :precision="0" v-model="formParams.min_money_2" controls-position="right" clearable placeholder="请输入提现金额Min"/>
              —
              <el-input-number :min="0" :max="999999999" :precision="0" v-model="formParams.max_money_2" controls-position="right" clearable placeholder="请输入提现金额Max"/>
            </el-form-item>
          </div>
        </div>
      </el-form>
    </div>
    <span slot="footer" class="dialog-footer">
      <el-button size="medium" @click="handleClose">取 消</el-button>
      <el-button size="medium" type="primary" @click="handleConfirm('robotForm')">确 认</el-button>
    </span>
  </el-dialog>
</template>

<script>
import {
  addRunning,
  editRunning
} from "@/api/game";
import {
  GAME_TYPE
} from '@/utils/enum'
export default {
  components: {},
  props: {
    show: {
      type: Boolean,
      default: false
    },
    data: {
      type: Object,
      default: function () {
        return {}
      }
    },
  },
  data () {
    return {
      GAME_TYPE,
      isShow: false,
      itemData:[
        { label: '游戏类型', key: 'a_robot_nametype' },
        { label: '房间号', key: 'a_robot_room' ,pass:true},
        { label: '机器人名称', key: 'a_robot_name' ,pass:true},
        { label: '机器人类型', key: 'a_robot_type' },
        { label: '提现金额', key: 'a_robot_money_1' ,pass:true},
        { label: '赢钱金额', key: 'a_robot_money_2' ,pass:true},
      ],
      formParams: {
        a_robot_nametype:0,
        a_robot_room:0,
        a_robot_name:'',
        a_robot_type:1, //1-提现 2-赢钱
        a_robot_money_1:'',
        min_money_1:0,
        max_money_1:0,
        a_robot_money_2:'',
        min_money_2:0,
        max_money_2:0,
      },
      ruleForm: {
        a_robot_room: [{ required: true, trigger: 'blur', message: '请输入房间号', }],
        a_robot_name: [{ required: true, trigger: 'blur', message: '请输入机器人名称', }],
      },
      rechargeDataList:[
        {item: 1, num: 1}
      ],
      rechargeIndex:0
    }
  },
  computed: {},
  watch: {
    show: function () {
      let that = this;
      that.isShow = that.show
      if (that.data) {
        that.data.min_money_1=0
        that.data.max_money_1=0
        that.data.min_money_2=0
        that.data.max_money_2=0
        that.formParams = JSON.parse(JSON.stringify(that.data))
        if(that.formParams.a_robot_money_1){
          that.formParams.min_money_1=that.formParams.a_robot_money_1[0]
          that.formParams.max_money_1=that.formParams.a_robot_money_1[1]
        }
        if(that.formParams.a_robot_money_2){
          that.formParams.min_money_2=that.formParams.a_robot_money_2[0]
          that.formParams.max_money_2=that.formParams.a_robot_money_2[1]
        }
      } else {
        that.formParams = {
          a_robot_nametype:0,
          a_robot_room:0,
          a_robot_name:'',
          a_robot_type:1, //1-提现 2-赢钱
          a_robot_money_1:[],
          min_money_1:0,
          max_money_1:0,
          a_robot_money_2:[],
          min_money_2:0,
          max_money_2:0,
        }
      }
    },
  },
  mounted () {},
  methods: {
    // 确认
    handleConfirm (formvalue) {
      let that = this,params = JSON.parse(JSON.stringify(that.formParams));
      if(!params.a_robot_room){
        return that.$message.error('请输入正确的房间号')
      }
      params.a_robot_money_1=JSON.stringify([that.$public.mathNumberMultiply(params.min_money_1,10000),that.$public.mathNumberMultiply(params.max_money_1,10000)])
      params.a_robot_money_2=JSON.stringify([that.$public.mathNumberMultiply(params.min_money_2,10000),that.$public.mathNumberMultiply(params.max_money_2,10000)])
      that.$refs[formvalue].validate((valid) => {
        if (valid) {
          if (!params.id) {
            addRunning(params).then(function (res) {
              that.$message.success(res.msg)
              that.$emit('onHideDetails', true)
            }).catch((error) => {
              that.$message.error(error.msg)
            })
          } else {
            editRunning(params).then(function (res) {
              that.$message.success(res.msg)
              that.$emit('onHideDetails', true)
            }).catch((error) => {
              that.$message.error(error.msg)
            })
          }
        } else {
          return false;
        }
      });
    },
    // 取消
    handleClose () {
      this.$emit('onHideDetails', false)
    },
  }
}
</script>

<style scoped lang="scss">
.btn-box-add {
  width: 50px;
  margin-top: -20px;
  margin-right: -15px;
  text-align: center;
  .el-button {
    height: 28px;
  }
}
.btn-box-delete {
  width: 50px;
  margin-bottom: 20px;
  text-align: center;
  .el-button {
    height: 28px;
  }
}
</style>
